package com.kaifamiao.list;

import java.util.Stack;

public class StackTest {

    public static void main(String[] args) {

        Stack<String> stack = new Stack<>();

        System.out.println( stack.empty() );

        stack.push( "唐三藏" );
        System.out.println( stack );

        stack.push( "孙悟空" );
        System.out.println( stack );

        stack.push( "猪悟能" );
        System.out.println( stack );

        String top = stack.peek();
        System.out.println( top );
        System.out.println( stack );

        top = stack.pop();
        System.out.println( top );
        System.out.println( stack );

        System.out.println( stack.empty() );

        System.out.println( stack.search( "孙悟空" ) );
        System.out.println( stack.search( "唐三藏" ) );

        System.out.println( stack.pop() );
        System.out.println( stack.pop() );

        System.out.println( stack.search( "唐三藏" ) ); // -1
        // System.out.println( stack.peek() ); // java.util.EmptyStackException
        // System.out.println( stack.pop() ); // EmptyStackException

    }

}
